
const { exec } = require("child_process");
const  {existsSync} = require('fs')
const ora = require('ora')
function toUnixPath(paths){
  var homePath = paths.replace(/\\/g,'/')
  return homePath+'/.temp'
}
function templateAction(name) {
  //用户根目录
  let tempPath = toUnixPath(process.env.HOME)+'/'+name//本地缓存路径
  if(existsSync(tempPath)){//判断是否存在缓存路径
    return tempPath
  }
  const spinner = ora()
  spinner.text="下载中..."
  spinner.start()
  // 这是模板项目的仓库地址
  const url = "git@gitee.com:lagoufed/lagoufed-e-task.git";
  // 克隆项目
  exec(`git clone ${url} ${tempPath}`, (error, stdout, stderr) => {
    if (error) {
      console.log(error);
      process.exit();
    }
    console.log("Success");
    spinner.succeed('下载成功')
    process.exit();
  });
  return tempPath
}
module.exports = {templateAction}